/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BuscarDCS.java
 *
 * Created on 23/01/2009, 12:39:31 AM
 */

package UIDelNegocio;

import LogicaDeNegocio.Main;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author Anya
 */
public class BuscarDCS extends javax.swing.JFrame {
public static String name="";
public static String tipo="";
public static int opc;
    /** Creates new form BuscarDCS */
    public BuscarDCS(String name1,String tipo1,int opc1) {
        name= name1;
        tipo= tipo1;
        opc = opc1;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("WellDressing");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel1.setText("Departamentos, Clases y Subclases");

        jScrollPane1.setViewportView(jList1);

        jButton1.setText("Cerrar");
        jButton1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Tipo: ");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Departamentos", "Clases", "Subclases" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Nombre:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jLabel1)
                .addContainerGap(86, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addGap(36, 36, 36))
            .addGroup(layout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(28, 28, 28))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)))
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(96, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addGap(43, 43, 43)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(opc != 1)//eliminar
        {
            Main control= new Main();
            String nombre= jList1.getSelectedValue().toString();
            int a;

            if(jComboBox1.getSelectedItem().equals("Subclases"))
            {
                a= control.borrarSubclase(nombre);
                if (a == 0)
                {
                    JOptionPane.showMessageDialog(null, "La subclase tiene productos asociados, no se puede eliminar", "alert", JOptionPane.ERROR_MESSAGE);
                }
                else
                {
                    JOptionPane.showMessageDialog(null, "Eliminada exitosamente", "WellDressing", JOptionPane.INFORMATION_MESSAGE);
                }

            }
            else if(jComboBox1.getSelectedItem().equals("Clases"))
            {
                a= control.borrarClase(nombre);
                if(a == 0)
                    JOptionPane.showMessageDialog(null, "Una subclase de esta Clase tiene productos asociados, no se puede eliminar", "alert", JOptionPane.ERROR_MESSAGE);
                else
                {
                    JOptionPane.showMessageDialog(null, "Eliminada exitosamente", "WellDressing", JOptionPane.INFORMATION_MESSAGE);
                }
            }
            else
            {
                a= control.borrarDepartamento(nombre);
                if(a == 0)
                    JOptionPane.showMessageDialog(null, "Una subclase de esta Clase tiene productos asociados, no se puede eliminar", "alert", JOptionPane.ERROR_MESSAGE);
                else
                {
                    JOptionPane.showMessageDialog(null, "Eliminada exitosamente", "WellDressing", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        }
        Adminis vent= new Adminis(name,tipo);
        vent.setVisible(true);
        this.setVisible(false);
}//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        if (opc == 1) {
            jButton1.setText("Cerrar");
            jLabel1.setText("Ver Departamentos, Clases o Subclases");
            jLabel3.setText("Nombre");
        } else {
            jLabel1.setText("Eliminar Departamentos, Clases o Subclases");
            jButton1.setText("Eliminar");
            jLabel3.setText("Seleccione el que desea eliminar");
        }
    }//GEN-LAST:event_formWindowActivated

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        Main control= new Main();
        int aux= 0;
        int i=0;
        Vector data1= new Vector();

        if(jComboBox1.getSelectedItem().equals("Subclases"))
        {
            i= (control.consultarSubclase2().getItemCount())+1;
            while(aux <i)
            {
                data1.add(aux,control.consultarSubclase2().getItemAt(aux));
                aux++;
            }
            jList1.setListData(data1);
        }
        else if(jComboBox1.getSelectedItem().equals("Clases"))
        {
            i= control.consultarClase2().getItemCount()+1;
            while(aux <i)
            {
                data1.add(aux,control.consultarClase2().getItemAt(aux));
                aux++;
            }
            jList1.setListData(data1);
        }
        else
        {
            i= control.consultarDepartamento2().getItemCount()+1;
            while(aux <i)
            {
                data1.add(aux,control.consultarDepartamento2().getItemAt(aux));
                aux++;
            }
            jList1.setListData(data1);
        }
    }//GEN-LAST:event_jComboBox1ActionPerformed

    /**
    * @param args the command line arguments
   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BuscarDCS().setVisible(true);
            }
        });
    } */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
